<%@page	import="java.util.ArrayList,com.alibaba.dubbo.demo.bean.SysDeptInfo"%>
<%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<%@page import="java.lang.Integer"%>
<%@page import="java.lang.String"%>
<%@page	import="com.point.community.bean.dwzPageData"%>
<%
	 dwzPageData dwzData;
     if(request.getSession().getAttribute("upperDeptDwzData")!=null)
     	dwzData =(dwzPageData)request.getSession().getAttribute("upperDeptDwzData"); 
     else
     	dwzData = new dwzPageData();
     String sdeptrightid = (String)request.getSession().getAttribute("deptrightids");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script src="jquery-1.4.1.js"></script>  
<script type="text/javascript">
$(function() {
        oldTableBack("depttable");
});
//已选带回的方法
function oldTableBack(tableId) {
        //获取已选内容
        var oldIds=$.pdialog._op.oldIds;
        var checkList=[];
        if(oldIds!=null&&oldIds!=undefined&&oldIds!=''){
            //得到已选列表
            checkList=oldIds.split(',');
        }
        $("#"+tableId).find("tr").each(function (i) {
            //是否已选判断
            if($.inArray($(this).attr("rel"), checkList)!=-1) {
                //复选框选中
                $(this).find('input[name=bringBacks]').attr("checked", true);
            }
        });
    }
    
    $("#depttable tr").each(function(){    
            $(this).children().click(function(e){    
                $(e.target).parent("tr.item").each(function(){  
                    if($(this).find(":checkbox").is(":checked")){  
                        $(this).find(":checkbox").attr("checked",false);  
                    }else{  
                        $(this).find(":checkbox").attr("checked",true);  
                    }  
                });  
            });    
        });  
</script>
<div class="pageHeader">
    <form id="pagerForm" rel="pagerForm" onsubmit="return dwzSearch(this, 'dialog');" action="webQueryDeptInfoLookup" method="post">
        <input type="hidden" name="pageNum" value="<%=dwzData.currentPage%>" />
        <input type="hidden" name="numPerPage" value="<%=dwzData.numPerPage%>" /> 
        <input type="hidden" name="method" value="page" />
    </form>
</div>
<div class="pageContent"  width="300" height="260">
    <table class="table" id="depttable" layoutH="108">
		<thead>
			<tr>
			<!-- <th width="40">序号</th>  -->	
				<th width="60">部门编号</th>
				<th width="120">部门名称</th>
				<th width="80">上级部门</th>
				<th width="80">负责人</th>
				<th width="120">电话</th>
				<th width="160">备注</th>
				<!--<th width="80">选择</th> -->
			</tr>
		</thead>
		<tbody id="depttbody">
			<% 
				int nIndex = 1;
			%>
			<s:iterator value="#session.sysUpperDept" status="m">
				<tr target="sid_user" rel="<s:property value="deptid" />" class="item" name="deptitem">
					<td><input type="checkbox" name="bringBacks" value="<s:property value='deptid' />" valstr="<s:property value="deptname" />" /><s:property value="deptid" /></td> 
					<td name="deptname"><s:property value="deptname" /></td>
					<td><s:property value="upperid" /></td> 
					<td><s:property value="manager" /></td>
					<td><s:property value="phone" /></td>
					<td><s:property value="remark" /></td>
				<!-- 		<td>
				 <a class="btnSelect" href="javascript:$.bringBack({deptid:'<s:property value="deptid" />', deptname:'<s:property value="deptname" />', orgNum:'<s:property value="deptid" />'})" title="查找带回">选择</a>
				</td>  -->
				</tr>
			</s:iterator>
		</tbody>
	</table>
	<div class="panelBar">
        <div class="pages">
            <span>显示</span>
            <select class="combox" name="numPerPage" onchange="navTabPageBreak({numPerPage:this.value})">
                <option value="10" <s:if test="10 == #session.numPerPage">selected="selected"</s:if>>10</option>
                <option value="20" <s:if test="20 == #session.numPerPage">selected="selected"</s:if>>20</option>
                <option  value="50"  <s:if test="50 == #session.numPerPage">selected="selected"</s:if>>50</option>
                <option  value="100"  <s:if test="100 == #session.numPerPage">selected="selected"</s:if>>100</option>
            </select>
            <span>条，共<%=dwzData.totalCount%>条</span>
        </div>
        <div class="pagination" targetType="navTab" totalCount= "<%=dwzData.totalCount%>" numPerPage="<%=dwzData.numPerPage%>" pageNumShown="<%=dwzData.pageNumShown%>" currentPage="<%=dwzData.currentPage%>" ></div>
    </div>
    <div class="formBar">
			<ul>
				<li><div class="buttonActive"><div class="buttonContent"><button type="button" onclick="btnSelect()">选择</button></div></div></li>
				<li>
					<div class="button"><div class="buttonContent"><button type="button" class="close">取消</button></div></div>
				</li>
			</ul>
	</div>
<script type="text/javascript">
  function btnSelect()
  {
	  	var strdeptids="",strdepts="";
	  	$(":checkbox:checked").each(function(){
		  var id = $(this).val();
		  var name = $(this).attr('valstr');
		  if(strdeptids=="")
		  	strdeptids +=id;
		  else
		   strdeptids +=","+id;
		   
		 if(strdepts=="")
		  	strdepts +=name;
		  else
		   strdepts +=","+name;
		}); 
		
     var jsonstr = '{"deptrightid":"'+strdeptids+'","deptright":"'+strdepts+'"}';
     var jsonObj = JSON.parse(jsonstr);
     //alert(jsonObj);
     $.bringBack(jsonObj);
  }
  $().ready(function() {
  		var ids = '<%=sdeptrightid%>'.split(',');
		$(":checkbox").each(function(){
		  var id = $(this).val();
		  if(ids.indexOf(id)>=0)
		  	$(this).attr('checked',true)
		  else
		    $(this).removeAttr('checked');
		}); 
  });
</script>
</div>